<%@page import="cn.jekun.component.base.utils.EncryptUtil"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="cn.jekun.component.base.spring.SpringUtils"%>
<%@page import="cn.jekun.component.shop.service.OrderService"%>
<%@page import="cn.jekun.web.shop.bean.Order"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/admin/public/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="en">    
<head>
<title>订单打印</title><meta charset="UTF-8" />
<link rel="stylesheet" href="${ctx}/admin/css/bootstrap.min.css" />
<link rel="stylesheet" href="${ctx}/admin/css/matrix-style.css" />
<script type="text/javascript" src="${ctx}/admin/js/base/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx}/admin/js/base/LodopFuncs.js"></script> 

<%
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", -10); 
	response.setHeader("Access-Control-Allow-Origin","*");  

	String orderId = request.getParameter("orderId");
	OrderService orderService = SpringUtils.getBean(OrderService.BEAN_NAME);
	cn.jekun.web.shop.service.OrderService orderServicea  = SpringUtils.getBean(cn.jekun.web.shop.service.OrderService.BEAN_NAME);
	JSONObject jsonObject = orderService.getOrder(orderId);
	Order order = orderServicea.getOrder(orderId);
	
	request.setAttribute("order", order);
	request.setAttribute("items", jsonObject.get("items"));
	//request.setAttribute("orderItems", jsonObject.get("orderItems"));
	
	request.setAttribute("baseShopId", EncryptUtil.encodeBase64(order.getShopId()));
	request.setAttribute("businessId", order.getBusinessId());
	
	String ptype=order.getPrintType();//1商户联,2客户联,3商户和客户联
	if(ptype==null || ptype.length()==0){
		ptype = "3";
	}
%>

<script>
$(function() {
	$("#btnpri").click();
});


var orderId='${param.orderId}';
var businessId=<%=order.getBusinessId() %>;
var shopId='${baseShopId}';
	function toPrint(){
		var strFullPath=window.document.location.href;
        var strPath=window.document.location.pathname;
        var pos=strFullPath.indexOf(strPath);
        var prePath=strFullPath.substring(0,pos);
        var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
        var webPath=prePath+postPath;
		
		LODOP=getLodop();
		var hheight = document.getElementById("print00").scrollHeight ;
		
		LODOP.SET_PRINTER_INDEXA("XP-58");//设置打印机
		LODOP.ADD_PRINT_URL(0,0,"100%","100%",webPath+"/admin/printOrder1.jsp?orderId="+orderId);
		LODOP.SET_PRINT_STYLEA(0,"HOrient",3);
		LODOP.SET_PRINT_STYLEA(0,"VOrient",3);
		
		<%if("2".equals(ptype) || "3".equals(ptype)){ %>
		if(businessId == '00' || businessId == '14'){
			var bheight = Math.floor(hheight/770);
			
			var lheight = 0;
			if(bheight > 0){
				lheight = hheight - bheight*770+30;
			}else{
				lheight = hheight+30;
			}
			
			var page = bheight+1;
			
			var iheight = lheight + 120;
			if(iheight > 770){
				LODOP.NEWPAGEA();
				page=page+1;
				LODOP.ADD_PRINT_BARCODE(0,35,120,120,"QRCode","http://www.storeme.cn/mall/reg?s="+shopId);
				LODOP.SET_PRINT_STYLEA(0,"PageIndex",page);
			}else{
				LODOP.ADD_PRINT_BARCODE(lheight,35,120,120,"QRCode","http://www.storeme.cn/mall/reg?s="+shopId);
				LODOP.SET_PRINT_STYLEA(0,"PageIndex",page);
			}
			
		}
		<%}%>
		LODOP.SET_SHOW_MODE("MESSAGE_GETING_URL","true");
		LODOP.SET_SHOW_MODE("MESSAGE_PARSING_URL","true");
		LODOP.PRINT();	
		//LODOP.PREVIEW();//打印预览
	}
</script>
</head>
<body  style='background-color:#fff; margin-left: 0px;margin-right: 0px; height:auto;' leftmargin=0 rightmargin=0>
	<div class="print"><button id="btnpri" class="noprint btn btn-success" style="position:absolute;top:20px;left:230px;"  onclick="toPrint()">打印</button>
		<div class="print printOrder" id="print00" style="width:180px;">
			<c:if test="${order.businessId == '00' }">
    			<%if("1".equals(ptype) || "3".equals(ptype)){ %>
    			<h3 class="text-center"><%=order.getShopName() %></h3>
				<p class="text-center">(商户留存联)</p>
				
				<div class="printOrder-top">
				<p>单号：<span><%=order.getOrderId() %></span></p>
				<p>时间：<span><%=jsonObject.get("orderDate") %></span></p>
				<p>收货人：<span><%=order.getShipName() %></span></p>
				<p>收货人手机：<span><%=order.getShipMobile() %></span></p>
				<p>收货地址：<span><%=order.getShipAddress() %></span></p>
				<p>支付方式：<span><%=jsonObject.get("paymentName") %></span></p>
				<p>订单状态：<span><%=order.getStatusName() %></span></p>
				<p>配送时间：<span><%=order.getShipTime() %></span></p>
				<p>用户留言：<span><%=jsonObject.get("leaveMessage") %></span></p>
				</div>
				
				<div class="printOrder-main">
				<table>
				<colgroup>
				<col width="60%" />
				<col/>
				<col/>
				</colgroup>
				<tbody>
				<tr>
				<th>商品</th>
				<th>单价*数量</th>
				<th>金额</th>
				</tr>
				<c:forEach var="list" items="${items}" varStatus="st">
					<tr valign="top">
					<td colspan="3">${st.count} ${list.merchandiseName}</td>
					</tr>
					<tr valign="top">
					<td align="left">${list.barcode}</td>
					<td align="left" class="white-space:nowrap;" nowrap="nowrap">${list.price}*${list.nums}</td>
					<td align="right" class="white-space:nowrap;" nowrap="nowrap">${list.amount}</td>
					</tr>
				</c:forEach>
				</tbody>
				</table>
				</div>
				<div class="printOrder-btm clearfix">
				<div class="clearfix"><span class="pull-left">总计：</span><span class="pull-right"><%=order.getTotalAmount() %></span></div>
				<%
					if(order.getPayTime() != null){%>
						<div class="clearfix"><span class="pull-left">已付：</span><span class="pull-right"><%=order.getTotalAmount() %></span></div>
					<%}else{%>
						<div class="clearfix"><span class="pull-left">已付：</span><span class="pull-right">0</span></div>
					<%}%>
				<div class="clearfix CustomerSignature"><span class="pull-left">客户签名：</span>
				<div class="underline pull-left"></div>
				</div>
				</div>
				<div class="printOrder-foot text-center">
				<p>欢迎再次光临<%=order.getShopName() %></p>
				<p>地址：<%=order.getShopAddress() %></p>
				<p>电话：<%=order.getShopPhone() %></p>
				<p>业务咨询：4000290823</p>
				</div>
				<%--分隔符 --%>
				<div style="height:1px; width:100%; border-bottom:1px dashed #000;"></div>
				<%} %>
				<%if("2".equals(ptype) || "3".equals(ptype)){ %>
				<h3 class="text-center"><%=order.getShopName() %></h3>
				<p class="text-center">(顾客留存联)</p>
				
				<div class="printOrder-top">
				<p>单号：<span><%=order.getOrderId() %></span></p>
				<p>时间：<span><%=jsonObject.get("orderDate") %></span></p>
				<p>收货人：<span><%=order.getShipName() %></span></p>
				<p>收货人手机：<span><%=order.getShipMobile() %></span></p>
				<p>收货地址：<span><%=order.getShipAddress() %></span></p>
				<p>支付方式：<span><%=jsonObject.get("paymentName") %></span></p>
				<p>订单状态：<span><%=order.getStatusName() %></span></p>
				<p>配送时间：<span><%=order.getShipTime() %></span></p>
				<p>用户留言：<span><%=jsonObject.get("leaveMessage") %></span></p>
				</div>
				
				<div class="printOrder-main">
				<table>
				<colgroup>
				<col width="60%" />
				<col/>
				<col/>
				</colgroup>
				<tbody>
				<tr>
				<th>商品</th>
				<th>单价*数量</th>
				<th>金额</th>
				</tr>
				<c:forEach var="list" items="${items}" varStatus="st">
					<tr valign="top">
					<td colspan="3">${st.count} ${list.merchandiseName}</td>
					</tr>
					<tr valign="top">
					<td align="left">${list.barcode}</td>
					<td align="left" class="white-space:nowrap;" nowrap="nowrap">${list.price}*${list.nums}</td>
					<td align="right" class="white-space:nowrap;" nowrap="nowrap">${list.amount}</td>
					</tr>
				</c:forEach>
				</tbody>
				</table>
				</div>
				<div class="printOrder-btm clearfix">
				<div class="clearfix"><span class="pull-left">总计：</span><span class="pull-right"><%=order.getTotalAmount() %></span></div>
				<%
					if(order.getPayTime() != null){%>
						<div class="clearfix"><span class="pull-left">已付：</span><span class="pull-right"><%=order.getTotalAmount() %></span></div>
					<%}else{%>
						<div class="clearfix"><span class="pull-left">已付：</span><span class="pull-right">0</span></div>
					<%}%>
				</div>
				<div class="printOrder-foot text-center">
				<p>欢迎再次光临<%=order.getShopName() %></p>
				<p>地址：<%=order.getShopAddress() %></p>
				<p>电话：<%=order.getShopPhone() %></p>
				<p>业务咨询：4000290823</p>
				</div>
				
				<div class="printOrder-foot text-center">
				<p>我家微店在这里</p>
				<p>http://www.storeme.cn</p>
				</div>
				<%--分隔符 --%>
				<div style="height:1px; width:100%; border-bottom:1px dashed #000;"></div>
				<%} %>
		    </c:if>
		    
		</div>
	</div>
</body>

</html>
